<?php
class Npn_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
        $this->load->database();
    }
    //获取当天商品信息
    function getGoodsArray(){
        //SELECT c1.*,a.id a_id,a.userName FROM priceninepointnine c1 LEFT JOIN admin a ON c1.updater=a.userName WHERE c1.publishDate=CURDATE() AND c1.endTime > UNIX_TIMESTAMP() AND c1.status=1 AND c1.isDel!=1 ORDER BY c1.sort
        $date = date("Y-m-d");//日期：当天
        $this->db->select('c.*,a.id a_id,a.userName');
        $this->db->from('priceninepointnine c');
        $this->db->join('admin a', 'c.updater = a.userName', 'left');
        $this->db->where(array('c.publishDate'=>$date, 'c.status'=>1, 'c.isDel !='=>1));
        $this->db->order_by('c.sort ASC,c.id ASC');
        $query = $this->db->get();
        $goodsArray = $query->result_array();
        //如果没有数据 ，取前一天的数据
        if (!$goodsArray) {
            $date = date("Y-m-d",strtotime("-1 day"));//日期：前一天
        	$this->db->select('c.*,a.id a_id,a.userName');
            $this->db->from('priceninepointnine c');
            $this->db->join('admin a', 'c.updater = a.userName', 'left');
            $this->db->where(array('c.publishDate'=>$date, 'c.status'=>1, 'c.isDel !='=>1));
            $this->db->order_by('c.sort ASC,c.id ASC');
            $query = $this->db->get();
            $goodsArray = $query->result_array();
        }
        return array($goodsArray,$date);
    }
    //根据说说推广获取的商品
    function firstgoods($id){
    	$this->db->select('c.*,a.id a_id,a.userName');
    	$this->db->from('priceninepointnine c');
    	$this->db->join('admin a', 'c.updater = a.userName', 'left');
    	$this->db->where('c.id',$id);
    	$query = $this->db->get();
    	$goodsArray = $query->row_array();
    	return $goodsArray;
    }
	//商品的点击
    function AjaxGoodsClick($id){
    	$this->db->set("clickNum","IFNULL(clickNum+1,1)",false);
    	$this->db->where("id",$id);
    	$this->db->update("priceninepointnine");
    	return $this->db->affected_rows();
    }
}